<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="config-form">
                <div class="select-list">
                    <ul>
                        <li>
                            名称：<input type="text" name="categoryTitle"/>
                        </li>
                        <li>
                            描述：<input type="text" name="description"/>
                        </li>
                        <li>
                            推荐：<select name="support" th:with="type=${@dict.getType('blog_category_support')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" >
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()"
               >
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" >
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var prefix = ctx + "monitor/blacklist";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "黑名单",
            columns: [{
                checkbox: true
            }, {
                field: 'blacklistId',
                title: '类别ID'
            }, {
                field: 'ipAddr',
                title: 'IP地址',
                formatter: function (value, row, index) {
                    return $.table.tooltip(value);
                }
            }, {
                field: 'description',
                title: '封禁原因',
                formatter: function (value, row, index) {
                    return $.table.tooltip(value);
                }
            }, {
                field: 'count',
                title: '封禁后访问次数'
            }, {
                field: 'lastAccessTime',
                title: '最后访问时间',
            }, {
                field: 'lastAccessUrl',
                title: '最后访问地址',
            }, {
                field: 'createBy',
                title: '创建者',
            }, {
                field: 'createTime',
                title: '创建时间',
            }, {
                title: '操作',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-success btn-xs '  + '" href="#" onclick="remove(\'' + row.blacklistId + '\')"><i class="fa fa-edit"></i>移除黑名单</a> ');
                    return actions.join('');
                }
            }]
        };
        $.table.init(options);
    });

    function remove(id) {
        $.modal.confirm("确定移除该黑名单吗？", function () {
            var url = $.common.isEmpty(id) ? $.table._option.removeUrl : $.table._option.removeUrl.replace("{id}", id);
            if ($.table._option.type == table_type.bootstrapTreeTable) {
                $.operate.get(url);
            } else {
                var data = {"ids": id};
                $.operate.submit(url, "delete", "json", data);
            }
        });
    }

</script>
</body>
</html>